<template>
  <div>
    <basic-container>
      <el-form ref="form"
               :model="sizeForm"
               label-width="80px"
               size="mini"
               :inline="true">
        <el-form-item label="设备状态">
          <el-select v-model="sizeForm.state"
                     placeholder="全部">
            <el-option label="全部"
                       value=""></el-option>
            <el-option label="已启用"
                       :value="0"></el-option>
            <el-option label="已停用"
                       :value="1"></el-option>
            <el-option label="保养中"
                       :value="2"></el-option>
            <el-option label="校准中"
                       :value="3"></el-option>
            <el-option label="维修中"
                       :value="4"></el-option>
            <el-option label="已报废"
                       :value="5"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="借用/预约">
          <el-select v-model="sizeForm.appointment"
                     placeholder="全部">
            <el-option label="全部"
                       value=""></el-option>
            <el-option label="可预约"
                       :value="0"></el-option>
            <el-option label="可借用"
                       :value="2"></el-option>
            <el-option label="不可预约"
                       :value="1"></el-option>
            <el-option label="不可借用"
                       :value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="设备预警">
          <el-select v-model="sizeForm.maintainWaring"
                     placeholder="全部">
            <el-option label="全部"
                       value=""></el-option>
            <el-option label="维保"
                       :value="0"></el-option>
            <el-option label="监控"
                       :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="设备分类">
          <el-cascader v-model="seachEquipmentTypeIds"
                       :options="seachEquipmentType"
                       :props="{ expandTrigger: 'hover' }"
                       @change="equipmentTypeChange()"></el-cascader>
        </el-form-item>
        <el-form-item label="存放位置">
          <el-select v-model="sizeForm.location"
                     placeholder="全部">
            <el-option label="全部"
                       value=""></el-option>
            <el-option label="仓库"
                       :value="0"></el-option>
            <el-option label="实验室"
                       :value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item size="mini">
          <el-button type="primary"
                     @click="onSearch()">搜索</el-button>
          <el-button @click="sizeForm = {}, seachEquipmentTypeIds = []">清空</el-button>
        </el-form-item>
      </el-form>
      <avue-crud :option="tableOption"
                 :data="gridData"
                 :table-loading="tableLoading"
                 :page="page"
                 ref="crud"
                 @current-change="currentPage"
                 @size-change='sizeChange'
                 @selection-change='selectionChange'
                 v-show="isTaizhang == 0"
                 class="management-vue">
        <template slot-scope="scope"
                  slot="isRun">
          {{equipmentState(scope.row)}}
        </template>
        <!-- 借用 -->
        <template slot-scope="scope"
                  slot="options">
          {{appointment(scope.row.options)}}
        </template>
        <!-- 预警 -->
        <template slot-scope="scope"
                  slot="maintainCycle">
          {{calibration(scope.row)}}
        </template>
        <!-- 设备类别 -->
        <template slot-scope="scope"
                  slot="equipmentTypeId">
          {{comEqType(scope.row.equipmentTypeId)}}
        </template>
        <template slot-scope="scope"
                  slot="location">
          {{LocationName(scope.row)}}
        </template>
        <template slot-scope="scope"
                  slot="isMaintain">
          {{scope.row.isMaintain == 0? '是':'否'}}
        </template>
        <template slot-scope="scope"
                  slot="isMonitor">
          {{scope.row.isMonitor == 0? '是':'否'}}
        </template>
        <template slot-scope="scope"
                  slot="menuLeft">
          <template slot-scope="scope"
                    slot="last_mode">
            {{scope.row.last_maintain_date}}<span>/</span>{{scope.row.last_correct_date}}<span>/</span>{{scope.row.maintain_waring}}
          </template>
          <el-button type="primary"
                     size="small"
                     plain
                     @click.stop="addModelClick()">添加</el-button>
          <el-button type="primary"
                     size="small"
                     plain
                     @click.stop="stateModeBtn(0)">启用</el-button>
          <el-button type="primary"
                     size="small"
                     plain
                     @click.stop="stateModeBtn(1)">停用</el-button>

          <el-button type="primary"
                     size="small"
                     plain
                     @click.stop="stateModeBtn(2)">维保申请</el-button>
          <el-button type="primary"
                     size="small"
                     plain
                     @click.stop="stateModeBtn(3)">故障报停</el-button>
          <el-button type="primary"
                     size="small"
                     plain
                     @click.stop="stateModeBtn(4)">报废申请</el-button>

          <el-button type="primary"
                     size="small"
                     plain
                     @click.stop="typeManage()">设备类别管理</el-button>
        </template>
        <template slot-scope="scope"
                  slot="menuRight">
          <el-form :inline="true"
                   :model="searchForm"
                   class="demo-form-inline"
                   size="mini">
            <el-form-item label="仅显示能传输数据设备">
              <el-checkbox v-model="searchForm.checked"></el-checkbox>
            </el-form-item>
            <el-form-item label="">
              <el-input v-model="searchForm.coded"
                        placeholder="请输入设备编码"></el-input>
            </el-form-item>
            <el-form-item label="">
              <el-input v-model="searchForm.name"
                        placeholder="请输入设备名称"></el-input>
            </el-form-item>
            <el-form-item label="">
              <el-input v-model="searchForm.model"
                        placeholder="请输入设备型号"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary"
                         @click="searchFormSubmit()">搜索</el-button>
            </el-form-item>
          </el-form>
        </template>
        <template slot-scope="scope"
                  slot="menu">
          <el-button type="primary"
                     size="small"
                     plain
                     @click.stop="updModeBtn(scope.row,scope.index)">修改</el-button>
          <el-button type="primary"
                     size="small"
                     plain
                     @click.stop="tableDelBtn(scope.row,scope.index)">删除</el-button>
          <el-button type="primary"
                     size="small"
                     plain
                     @click.stop="seeModeBtn(scope.row,scope.index)">台账</el-button>
        </template>
      </avue-crud>
    </basic-container>
    <!-- //新增and 修改 -->
    <el-dialog :title="modelTitle"
               :visible.sync="addModel" center
               width="65%">
      <el-form ref="addForm"
               :model="addForm"
               :rules="addModelrules"
               label-width="100px"
               size="mini">
        <el-col :span="10">
          <el-form-item label="设备编码:"
                        prop="coded">
            <el-input v-model="addForm.coded"></el-input>
          </el-form-item>
          <el-form-item label="设备名称:"
                        prop="name">
            <el-input v-model="addForm.name"></el-input>
          </el-form-item>
          <el-form-item label="设备型号:"
                        prop="marking">
            <el-input v-model="addForm.marking"></el-input>
          </el-form-item>
          <el-form-item label="设备品牌:"
                        prop="brand">
            <el-input v-model="addForm.brand"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10"
                :offset="2">
          <el-form-item label="图片:"
                        prop="pictureUrl"
                        class="picture_url">

            <!-- <el-input v-model="addForm.picture_url"
                      hidden></el-input> -->
            <el-upload :action="actionUrl"
                       :headers="uploadHeaders"
                       name="file"
                       :show-file-list="false"
                       accept="image/*"
                       :on-success="handleAvatarSuccess"
                       :on-error="uploadError"
                       class="avatar-uploader">
              <img v-if="imageUrl"
                   :src="imageUrl"
                   class="avatar"
                   width="165px"
                   height="210px"
                   style="object-fit: cover;" />
              <i v-else
                 class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="供应商:"
                        prop="supplier">
            <el-input v-model="addForm.supplier"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10"
                :offset="2">
          <el-form-item label="设备类别:"
                        prop="equipmentType">
            <el-cascader v-model="equipmentTypeIds"
                         :options="equipmentType"
                        ></el-cascader>
            <!-- <el-select v-model="addForm.equipmentType"
                       placeholder="请选择">
              <el-option v-for="item in equipmentType"
                         :key="item.id"
                         :label="item.name"
                         :value="item.id">
              </el-option>
            </el-select> -->
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="购买价格:"
                        prop="price">
            <el-input v-model="addForm.price"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10"
                :offset="2">
          <el-form-item label="购买日期:"
                        prop="purchasing_date">
            <el-date-picker v-model="addForm.purchasing_date"
                            type="date"
                            placeholder="选择日期">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="联系方式:"
                        prop="phoneNum">
            <el-input v-model="addForm.phoneNum"></el-input>
          </el-form-item>
        </el-col>
         <el-col :span="10">
          <el-form-item label="设备Id:"
                        prop="deviceId">
            <el-input v-model="addForm.deviceId"></el-input> 
          </el-form-item>
        </el-col>
        <el-col :span="10" v-if="!getShebei && modelTitle!='添加设备'">
          <el-form-item label="智能插座Id:" prop="elcId">
             <el-select v-model="addForm.elcId"  
                placeholder="请选择">
                <el-option v-for="(item,index) in selectELList" 
                :label="item.name+'('+item.deviceId+')'" :key="index" 
                :value="item.deviceId"></el-option>
              </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-col :span="8">
            <el-form-item label="存放位置:"
                          prop="locations">
              <el-select v-model="addForm.locations" @change="qingNull"
                         placeholder="请选择">
                <el-option label="仓库"
                           :value="0"></el-option>
                <el-option label="实验室"
                           :value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8"
                  v-if="addForm.locations==0||addForm.locations==1">
            <el-form-item label="存放位置:"
                          prop="location">
              <el-select v-model="addForm.location"
                         placeholder="请选择">
                <el-option v-for="item in locationList"
                           :key="item.id"
                           :label="item.name"
                           :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8"
                  v-if="addForm.locations==0||addForm.locations==1">
            <el-form-item label="借用设置:"
                          prop="options">
              <el-select v-model="addForm.options"
                         placeholder="请选择">
                <el-option :label="'可预约'"
                           v-if="addForm.locations==1"
                           :value="0"></el-option>
                <el-option :label="'不可预约'"
                           v-if="addForm.locations==1"
                           :value="1"></el-option>
                <el-option :label="'可借用'"
                           v-if="addForm.locations==0"
                           :value="2"></el-option>
                <el-option :label="'不可借用'"
                           v-if="addForm.locations==0"
                           :value="3"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-col>
        <el-col :span="24">
          <el-form-item label="是否维护:"
                        prop="is_maintain">
            <el-radio v-on:change="radioChange()"
                      v-model.number="addForm.is_maintain"
                      :label="0">是</el-radio>
            <el-radio v-on:change="radioChange()"
                      v-model.number="addForm.is_maintain"
                      :label="1">否</el-radio>
          </el-form-item>
        </el-col>
        <el-col :span="24"
                v-if="addForm.is_maintain == 0">
          <el-col :span="8">
            <el-form-item label="保养周期（天）:"
                          prop="maintain_cycle">
              <el-input v-model.number="addForm.maintain_cycle"
                        property="保养周期（天）"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="效准周期（天）:"
                          prop="correct_cycle">
              <el-input v-model.number="addForm.correct_cycle"
                        property="效准周期（天）"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="维保预警（天）:"
                          prop="maintain_waring">
              <el-input v-model.number="addForm.maintain_waring"
                        property="维保预警（天）"></el-input>
            </el-form-item>
          </el-col>
        </el-col>
        <el-col :span="24">
          <el-form-item label="是否监控:"
                        prop="is_monitor">
            <el-radio-group v-model="addForm.is_monitor">
              <el-radio :label="0"
                        :value='0'>是</el-radio>
              <el-radio :label="1"
                        :value='1'>否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24"
                v-if="addForm.is_monitor ==0 ">
          <el-col :span="8">
            <el-form-item label="最小电压（v）:"
                          prop="voltage_waring">
              <el-input v-model="addForm.voltage_waring"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="最大电压（v）:"
                          prop="electricity_waring">
              <el-input v-model="addForm.electricity_waring"></el-input>
            </el-form-item>
          </el-col>
        </el-col>
        <el-col :span="24">
          <el-form-item label="数据传输:"
                        prop="is_transmission">
            <el-radio v-on:change="radioChange()"
                      v-model.number="addForm.is_transmission"
                      :label="0">是</el-radio>
            <el-radio v-on:change="radioChange()"
                      v-model.number="addForm.is_transmission"
                      :label="1">否</el-radio>
          </el-form-item>
        </el-col>
        <el-col :span='24'
                v-if="addForm.is_transmission == 0">
          <el-col :span="24">
            <el-col :span="10">
              <el-form-item label="传输方式:"
                            prop="mode">
                <el-radio v-on:change="radioChange()"
                          v-model.number="addForm.mode"
                          :label="0">多通道</el-radio>
                <el-radio v-on:change="radioChange()"
                          v-model.number="addForm.mode"
                          :label="1">单通道</el-radio>
              </el-form-item>
            </el-col>

            <el-col :span="24">
              <el-form-item label="接口类型:"
                            prop="interface_type">
                <el-radio v-on:change="radioChange()"
                          v-model.number="addForm.interface_type"
                          :label="0">TPC</el-radio>
                <el-radio v-on:change="radioChange()"
                          v-model.number="addForm.interface_type"
                          :label="1">串口</el-radio>
                <el-radio v-on:change="radioChange()"
                          v-model.number="addForm.interface_type"
                          :label="2">USB</el-radio>
                <el-radio v-on:change="radioChange()"
                          v-model.number="addForm.interface_type"
                          :label="3">其它</el-radio>
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="10">
            <el-form-item label="设备地址:"
                          prop="equipment_site">
              <el-input v-model="addForm.equipment_site"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="10"
                  :offset="2">
            <el-form-item label="通讯端口:"
                          prop="port">
              <el-input v-model="addForm.port"></el-input>
            </el-form-item>
          </el-col>
        </el-col>
        <el-col :span="24">
          <el-form-item label="是否启用:"
                        prop="is_run">
            <el-radio v-on:change="radioChange()"
                      v-model.number="addForm.is_run"
                      :label="0">是</el-radio>
            <el-radio v-on:change="radioChange()"
                      v-model.number="addForm.is_run"
                      :label="1">否</el-radio>
          </el-form-item>
        </el-col>
        <el-col :span="24"
                v-if="addForm.is_run ==1 ">
          <el-form-item label=""
                        prop="stop_cause">
            <el-radio v-on:change="radioChange()"
                      v-model.number="addForm.stop_cause"
                      :label="0">保养</el-radio>
            <el-radio v-on:change="radioChange()"
                      v-model.number="addForm.stop_cause"
                      :label="1">效准</el-radio>
            <el-radio v-on:change="radioChange()"
                      v-model.number="addForm.stop_cause"
                      :label="2">维修</el-radio>
            <el-radio v-on:change="radioChange()"
                      v-model.number="addForm.stop_cause"
                      :label="3">停用</el-radio>
            <el-radio v-on:change="radioChange()"
                      v-model.number="addForm.stop_cause"
                      :label="4">报废</el-radio>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="" label-width="0px" style="text-align: center">
            <el-button type="primary"
                       @click.native.prevent="addSubmit('addForm')">保存</el-button>
            <el-button @click.stop="addSubmitClose()">取消</el-button>
          </el-form-item>
        </el-col>
        <el-form-item class="zindex1">
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 启用/停用 -->
    <el-dialog :visible.sync="stateMode"
               width="45%"
               center>
      <el-row>
        <el-col :span="4"
                :offset="10">{{stateModeTitle}}</el-col>
      </el-row>
      <div v-if="stateMode">
        <el-row>
          <el-col :span="4">设备类别:</el-col>
          <el-col :span="8">{{comEqType(selectionRow.equipmentTypeId)}}</el-col>
          <el-col :span="4">设备编码:</el-col>
          <el-col :span="8">{{selectionRow.coded}}</el-col>
        </el-row>
        <el-row>
          <el-col :span="4">型号:</el-col>
          <el-col :span="8">{{selectionRow.marking}}</el-col>
          <el-col :span="4">品牌:</el-col>
          <el-col :span="8">{{selectionRow.brand}}</el-col>
        </el-row>
        <el-row>
          <!--<el-col :span="4">安装实验室:</el-col>-->
          <!--<el-col :span="8">{{selectionRow.laboratory == 'null' ? selectionRow.laboratory.name : '' }}</el-col>-->
          <el-col :span="4">设备名称:</el-col>
          <el-col :span="8"
                  v-if="selectionRow.name">{{selectionRow.name}}</el-col>
        </el-row>
        <!-- 购买价格 -->
        <!-- <el-row v-if="stateModeFormIs ==2">
          <el-row>
            <el-col :span="4">购买价格：</el-col>
            <el-col :span="8">{{selectionRow.marking}}</el-col>
            <el-col :span="4">首次启用时间：</el-col>
            <el-col :span="8">{{selectionRow.brand}}</el-col>
          </el-row>
        </el-row> -->
      </div>
      <!-- 停用 -->
      <el-row v-if="stateModeFormIs==1">
        <el-form ref="stateModeForm"
                 :model="stateModeForm"
                 size="mini">
          <el-form-item label="停用类型："
                        prop="stop_cause"></el-form-item>
          <el-form-item label=""
                        prop="stop_cause">
            <el-radio v-model.number="stateModeForm.stop_cause"
                      :label="0">保养</el-radio>
            <el-radio v-model.number="stateModeForm.stop_cause"
                      :label="1">效准</el-radio>
            <el-radio v-model.number="stateModeForm.stop_cause"
                      :label="2">维修</el-radio>
            <el-radio v-model.number="stateModeForm.stop_cause"
                      :label="3">停用</el-radio>
            <el-radio v-model.number="stateModeForm.stop_cause"
                      :label="4">报废</el-radio>
          </el-form-item>
        </el-form>
      </el-row>
      <!-- 维保申请 -->
      <el-row v-if="stateModeFormIs>=2">
        <el-form ref="newspaperStop"
                 :model="newspaperStop"
                 :rules="newspaperStopRules"
                 size="mini">
          <el-form-item :label="newspaperStop.typeTitle"
                        prop="type">
            <el-select v-model="newspaperStop.type"
                       placeholder="请选择">
              <el-option label="请选择"
                         value=""></el-option>
              <el-option label="保养"
                         v-if="stateModeFormIs == 2 || stateModeFormIs == 3"
                         :value="0"></el-option>
              <el-option label="校准"
                         v-if="stateModeFormIs == 2 || stateModeFormIs == 3"
                         :value="1"></el-option>
              <el-option label="维修"
                         v-if="stateModeFormIs == 2 || stateModeFormIs == 3"
                         :value="2"></el-option>
              <!-- 维保 -->
              <el-option v-if="stateModeFormIs == 3"
                         label="报废"
                         :value="3"></el-option>
              <el-option label="停用"
                         v-if="stateModeFormIs == 3"
                         :value="4"></el-option>
              <!-- 报废 -->
              <el-option v-if="stateModeFormIs == 4"
                         label="出售"
                         :value="0"></el-option>
              <el-option label="处理"
                         v-if="stateModeFormIs == 4"
                         :value="1"></el-option>
              <el-option label="其他"
                         v-if="stateModeFormIs == 4"
                         :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item :label="newspaperStop.docsTitle"
                        prop="docs">
            <el-input type="textarea"
                      rows='5'
                      v-model="newspaperStop.docs"></el-input>
          </el-form-item>
        </el-form>
      </el-row>
      <span slot="footer"
            class="dialog-footer">
        <el-button size="small"
                   @click="menuModeFormBtnClose()">关 闭</el-button>
        <el-button size="small"
                   type="primary"
                   @click="menuModeFormBtn()">{{stateModeBtnName}}</el-button>
      </span>
    </el-dialog>
    <!-- //设备类别管理 -->
    <!-- <el-dialog :visible.sync="typeMode"
               width="45%"
               title="设备类别">
      <el-tree :data="equipmentType"
               node-key="id"
               :expand-on-click-node="false">
        <span class="custom-tree-node"
              slot-scope="{ node, equipmentType }">
          <span>{{ node.label }}</span>
          <span>
            <el-button type="text"
                       size="mini"
                       @click="() => equipmentTypeUpdate(node, equipmentType)"> 修改 </el-button>
            <el-button type="text"
                       size="mini"
                       @click="() => equipmentTypeDelete(node, equipmentType)"> 删除 </el-button>
          </span>
        </span>
      </el-tree>
      <span slot="footer"
            class="dialog-footer">
        <el-button size="small"
                   type="primary"
                   @click="typeModeAdd = true">添加</el-button>
        <el-button size="small"
                   @click="typeMode = false">关 闭</el-button>
      </span>
    </el-dialog> -->

    <el-dialog :visible.sync="typeModeAdd"
               width="40%"
               title="添加分类">
      <el-form ref="stateModeForm"
               :model="stateModeForm"
               size="mini">
        <el-form-item label=""
                      prop="stop_cause">
          <el-select v-model="stateModeForm.state"
                     placeholder="请选择">
            <el-option label="默认"
                       value="0"></el-option>
            <el-option label="默认1"
                       value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label=""
                      prop="stop_cause">
          <el-input type="textarea"
                    :rows="2"
                    placeholder="在每个分类后面敲击 “ 回车键 ” “换行”，可批量添加分类。"
                    v-model="stateModeForm.state"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer"
            class="dialog-footer">
        <el-button size="small"
                   type="primary"
                   @click="typeModeAdd = false">添加</el-button>
        <el-button size="small"
                   @click="typeModeAdd = false">关 闭</el-button>
      </span>
    </el-dialog>

    <!-- 设备类管理 -->
    <el-dialog title="设备类别管理"
               :visible.sync="dialogTypeManageVisible"
               width="40%">
      <div>
        <div class="add-type">
          <el-button type="primary"
                     size="small"
                     @click="appendTreeType()">添加</el-button>
        </div>
        <el-tree :data="getDepartmentTree"
                 :props="treeOption"
                 :expand-on-click-node="false"
                 default-expand-all
                 @node-click="handleNodeClick()">
          <div class="custom-tree-node"
               slot-scope="{ node, data }">
            <span>{{ node.label }}</span>
            <span>
              <el-button type="text"
                         size="mini"
                         @click="() => addDepartment(node, data)">添加</el-button>
              <el-button type="text"
                         size="mini"
                         @click="() => editTree(node, data)">修改</el-button>
              <el-button type="text"
                         size="mini"
                         @click="() => removeTree(node, data)">删除</el-button>
            </span>
          </div>
        </el-tree>
      </div>
      <div slot="footer"
           class="dialog-footer"
           style="text-align:center">
        <el-button @click="dialogTypeManageVisible = false">关 闭</el-button>
      </div>
    </el-dialog>
    <!-- 添加分类 -->
    <el-dialog title="添加分类"
               :visible.sync="dialogFormTypeVisible"
               width="30%">
      <el-form ref="dialogFormType"
               :model="dialogFormType"
               :rules="rulesType"
               label-position="left"
               label-width="110px">
        <!-- <el-form-item label="项目分类："
                      prop="parentId">
          <el-cascader v-model="dialogFormType.parentId"
                       :options="getDepartmentTree"
                       :show-all-levels="false"
                       @change="handleTree"
                       :props="cascaderPeops"
                       style="width:100%">
            <template slot-scope="{ node, data }">
              <span>{{ data.label }}</span>
              <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
            </template>
          </el-cascader>
        </el-form-item> -->
        <el-form-item label="类别名称："
                      prop="content"
                      label-width="110px">
          <el-input v-model="dialogFormType.content"
                    type="textarea"
                    :autosize="{ minRows: 6, maxRows: 10 }"
                    placeholder="在每个分类后面敲击 “ 回车键 ” “换行”，可批量添加分类。"
                    @keyup.enter.native="changeInput"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer"
           class="dialog-footer"
           style="text-align:center">
        <el-button @click="dialogFormTypeVisible = false">关 闭</el-button>
        <el-button type="primary"
                   @click="handleAddType('dialogFormType')">确 认</el-button>
      </div>
    </el-dialog>
    <!-- 修改样品分类名字 -->
    <el-dialog title="修改分类"
               :visible.sync="dialogTypeTitleVisible"
               width="24%">
      <el-form ref="dialogTypeTitle"
               :model="dialogTypeTitle"
               :rules="rulesTypeTitle"
               label-width="80px"
               label-position="left">
        <el-form-item label="分类:"
                      prop="parentId">
          <el-cascader v-model="dialogTypeTitle.parentId"
                       :options="getDepartmentTree"
                       :change-on-select="true"
                       @change="handleTree"
                       :props="cascaderPeops"
                       style="width:100%">
            <template slot-scope="{ node, data }">
              <span>{{ data.label }}</span>
              <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
            </template>
          </el-cascader>
        </el-form-item>
        <el-form-item label="名称:"
                      prop="name">
          <el-input v-model="dialogTypeTitle.name"
                    placeholder=""></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer"
           class="dialog-footer"
           style="text-align:center">
        <el-button @click="dialogTypeTitleVisible = false">关 闭</el-button>
        <el-button type="primary"
                   @click="handleEditTypeTitle('dialogTypeTitle')">确 认</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { mapState, mapMutations, mapActions } from 'vuex'
import eleCalendar from 'ele-calendar'
import 'ele-calendar/dist/vue-calendar.css'
import { option, optionAdd, optionSelect, optionSelectForm, sbRules, jsonToArray, serverArr } from "@/const-personal/equipment/device/management.js"
import { getToken } from "@/util/auth";
import { deepClone, equipmentTypeTreeVChildrenNull, getDepartmentTreeOfId, DepartmentTreeVChildrenNull, getDepartmentTreeOfValue } from "@/util/util.js"
import { selectElAllNo } from "@/api/equipment/device/management";
import {
  getEquipmentList,
  getWarehouseList,
  getEquipmentType,
  addEquipment,
  deleteEquipment,
  updateEquipment,
  getLaboratoryList,
  upWalk,
  downBack,
  addMaintenanceAppointment, //
  addTrouble,
  addScrapApplication,
  ledger, //台账
  getDevList, //设备类别
  addDev,
  delDev,
  editDev
} from '@/api/equipment/device/management.js'
import { validatenull } from '@/util/validate'
import website from "@/const/website";
import {
  getUserList,
  getDepartmentList,
  getUserByRolesType,
  addUser,
  deleteRolesItem,
  updateUser,
  //部门
  addDepartment,
  updateDepartment,
  deleteDepartment,
  findByIdPicture
} from "@/api/sysSetup/uesr.js";

export default {
  data () {
    return {
      newspaperStop: { //报废申请
        type: '',
        docs: '',
        typeTitle: '',
        docsTitle: ''
      },
      newspaperStopRules: {
        type: [
          { required: true, message: '请选择类型', trigger: 'change' }
        ],
        docs: [
          { required: true, message: '请输入申请说明', trigger: 'blur' }
        ]
      },
      sizeForm: {
        state: '',
        maintainWaring: '',
        appointment: '',
        equipmentTypeId: '',
        location: '',
      },//top search
      isTaizhang: 0,//台账
      typeModeAdd: false,//类型模态框添加按钮
      uploadData: {},//上传图片附带参数
      stateMode: false,//修改状态
      stateModeBtnName: '',//启用模态框按钮名称
      stateModeTitle: '', //启用模态框名称
      stateModeForm: {},//启用模态表单数据
      stateModeFormIs: false,//启用模态框表单启用
      typeMode: false,//类型模态框
      activeName: 0,
      is_picture_urlClass: false,
      addModel: false,
      modelTitle: '',//设备模态标题
      addForm: {
        name: '',
        coded: '',
        marking: '',
        brand: '',
        elcId:'',
        deviceId:'',
        supplier: '',
        equipment_type_id: '',
        price: '',
        purchasing_date: '',
        is_maintain: -1,
        is_monitor: -1,
        radio: true,
        options: '',
        location: '',
        locations: '',
        is_run: -1,
        maintain_waring: '',
        correct_cycle: '',
        voltage_waring: '',
        electricity_waring: '',
        maintain_cycle: '',
        is_transmission: -1,
        interface_type: -1,
        equipment_site: '',
        stop_cause: '',
        mode: -1,
        pictureUrl: '',
        phoneNum: ''
      },
      //上传图片
      imageUrl: '',
      actionUrl: `${website.axiosUrl}/equipment/v1/upload`,
      uploadHeaders: {
        Authorization: getToken()
      },
      //仓库列表
      WarehouseList: [],
      LaboratoryList: [], //实验室列表
      equipmentType: [], //设备类型
      seachEquipmentType: [],
      seachEquipmentTypeIds: [],
      equipmentTypeIds: [],
      addModelrules: sbRules,
      selectionRow: { id: '' },
      searchForm: {
        name: '',
        checked: '',
        model: '',
        coded: ''
      },
      is_update: false, //修改标识
      updateId: null,
      tableOption: option, //表格设置属性
      tableData: [], //表格的数据
      tablePage: 1,
      tableLoading: false,
      tabelObj: {},
      page: {
        total: 0, //总页数
        currentPage: 1, //当前页数
        pageSize: 10,//每页显示多少条
        pageSizes: [5, 10, 20]//
      },
      grade: {
        box: false,
        check: []
      },
      gridData: [],
      shebeiList:[],
        // 部门管理
        dialogTypeManageVisible: false,
        treeOption: {
          children: "children",
          label: "label"
        },
        treeData: [],
        //增加部门
        dialogFormTypeVisible: false,
        dialogFormType: {},
        rulesType: {
          parentId: [
            { required: true, message: "请选择部门分类", trigger: "change" }
          ],
          content: [{ required: true, message: "请输入分类", trigger: "blur" }]
        },
        // 多级联动配置
        cascaderPeops: {
          value: "id",
          label: "label"
        },
        // 修改部门标题
        dialogTypeTitleVisible: false,
        dialogTypeTitle: { name: "", parentId: [] },
        rulesTypeTitle: {
          name: [{ required: true, message: "不能为空", trigger: "blur" }],
          parentId: [{ required: true, message: "不能为空", trigger: "change" }]
        },
        is_update: false, //修改标识
        getDepartmentTree: [],
        getDepartmentTreeSelect:[],
        devTypeArr: [],//数组设备类别 新
        isAsEl:null,
        selectELList:[],
        copySelectELList:[]

    }
  },
  components: {
    eleCalendar
  },
  created () {
    this._getDepartmentList(); //分类
    this.handleList();
    this._getModelSelectData();
    this.getshebeiList()
    this.getSelectElAllNo()
  },
  mounted() {
  },
  watch:{
  //  'addForm.deviceId'(){
  //     this.selectELList=  this.copySelectELList.filter((item)=>{
  //                 return item.deviceId != this.addForm.deviceId
  //        })
  //  }
  },
  computed: {
    getShebei(){
         let list=  this.equipmentType.filter((item)=>{
           return item.id==this.equipmentTypeIds
         })
         if(list.length>0){
           if(list[0].label=='智能插座'||this.isAsEl==1){
               this.addForm.elcId =''
                this.selectELList=  this.copySelectELList.filter((item)=>{
                  return item.deviceId != this.addForm.deviceId
                })
               return true
           }else{

             return false
           }
         }else{
            return false
         }
    },
    //设备状态转换
    equipmentState () {
      return ((state) => {
        let result = ''
        switch (state.isRun) {
          case 0:
            result = '已启用'
            break;
          case 1:
            switch (state.stopCause) {
              case 0:
                result = '保养中'
                break;
              case 1:
                result = '校准中'
                break;
              case 2:
                result = '维修中'
                break;
              case 3:
                result = '已停用'
                break;
              case 4:
                result = '已报废'
                break;
            }
        }
        return result
      })
    },
    //预约
    appointment () {
      return ((option) => {
        let result = ''
        switch (option) {
          case 0:
            result = '可预约'
            break;
          case 1:
            result = '不可预约'
            break;
          case 2:
            result = '可借用'
            break;
          case 3:
            result = '不可借用'
            break;
        }
        return result
      })
    },
    locationList () {
      return (this.addForm.locations == 1 ? this.LaboratoryList : this.WarehouseList)
    },
    //保养 预警  校准
    calibration () {
      return ((scope) => {
        if (scope.maintainCycle && scope.correctCycle && scope.maintainWaring) {
          return (scope.maintainCycle + '/' + scope.correctCycle + '/' + scope.maintainWaring)
        } else {
          return ''
        }
      })
    },
    // devTypeArr () {
    //   return jsonToArray(this.equipmentType)
    // },
    // 设备类别
    comEqType () {
      return ((type) => {
        for (let i = 0; i < this.devTypeArr.length; i++) {
          if (this.devTypeArr[i].id == type) {
            // console.log("name:" + this.equipmentType[i].label)
            return this.devTypeArr[i].name
          }
        }
      })
    },
    //存放位置
    LocationName () {
      return ((location) => {
        return location.location ? '实验室' : '仓库';
        // return location.warehouseId ? location.warehouse.name : location.laboratory.name
      })
    },
  },
  methods: {
    ...mapMutations('equipmentLedger', ['setEquipmentLedger']),
    //添加设备model
    addModelClick () {
      this.addModel = true;
      this.isAsEl=1
      this.modelTitle = '添加设备'
      this.is_update = false
      //this.addForm = { options: ''}
      this.imageUrl = null
    },
    getSelectElAllNo(){
      selectElAllNo().then((res)=>{
        this.selectELList = res.data.data
        this.copySelectELList = res.data.data
      })
    },
    _getModelSelectData () {
      getWarehouseList().then(res => { //仓库列表
        if (res.data.code === 200) {
          this.WarehouseList = res.data.data
        } else {
          this.$notify.error(res.data.message)
        }
      })
      // getDevList().then(res => { //设备类型
      //   if (res.data.code === 200) {
      //     const { data } = res.data
      //     this.equipmentType = equipmentTypeTreeVChildrenNull(data)
      //     console.log(this.equipmentType);
      //   } else {
      //     this.$notify.error(res.data.message)
      //   }
      // })
      getLaboratoryList().then(res => { //实验室列表
        if (res.data.code === 200) {
          this.LaboratoryList = res.data.data
        } else {
          this.$notify.error(res.data.message)
        }
      })
    },
    //设备类别变化
    equipmentTypeChange (val) {
      // console.log(val);
      // console.log(this.sizeForm);
      this.sizeForm.equipmentTypeId = this.equipmentTypeIds[this.equipmentTypeIds.length - 1] || null
    },
    //top  搜索
    onSearch () {
      this.handleList(this.sizeForm)
      // this.sizeForm = {}
    },
    addSubmitClose () {
      this.$refs['addForm'].resetFields();
      this.equipmentTypeIds = [];
      this.imageUrl = '';
      this.addModel = false
    },
    //确认添加设备
    addSubmit (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let data = {
            coded: this.addForm.coded, //编码
            deviceId: this.addForm.deviceId, //编码
            elcId: this.addForm.elcId, //编码
            name: this.addForm.name, //名称
            marking: this.addForm.marking, //型号
            brand: this.addForm.brand, //品牌
            supplier: this.addForm.supplier, //供应商
            price: this.addForm.price, // 价格
            equipmentTypeId: typeof this.addForm === 'number' ? this.addForm.equipmentType : this.equipmentTypeIds[this.equipmentTypeIds.length-1], //设备类型
            purchasingDate: this.$moment(this.addForm.purcequipmentTypehasing_date).format('YYYY-MM-DD'), //购买时间
            // warehouseId: typeof this.addForm.location === 'number' ? this.addForm.location : this.warehouseId, //存放位置
            // laboratoryId: typeof this.addForm.location === 'number' ? this.addForm.location : this.laboratoryId,
            location: this.addForm.locations,//存放类型
            options: this.addForm.options, //借用设置
            isMaintain: this.addForm.is_maintain, //是否维保
            maintainCycle: this.addForm.maintain_cycle, //保养周期
            correctCycle: this.addForm.correct_cycle, //校准周期
            maintainWaring: this.addForm.maintain_waring,// 维保预警
            isMonitor: this.addForm.is_monitor,//是否监控
            voltageWaring: this.addForm.voltage_waring, //是否预警
            electricityWaring: this.addForm.electricity_waring,//电流预警
            isTransmission: this.addForm.is_transmission,//是否传输
            mode: this.addForm.mode,//传输方式
            interfaceType: this.addForm.interface_type,//接口类型
            equipmentSite: this.addForm.equipment_site,//设备地址
            port: this.addForm.port,//通讯端口
            isRun: this.addForm.is_run,//是否启用
            stopCause: this.addForm.stop_cause, //停用类型,
            pictureUrl: this.addForm.pictureUrl, //图片
            phoneNum: this.addForm.phoneNum  //电话号码
          }
          if (this.addForm.locations === 1) {
            data['laboratoryId'] = typeof this.addForm.location === 'number' ? this.addForm.location : this.laboratoryId
          } else {
            data['warehouseId'] = typeof this.addForm.location === 'number' ? this.addForm.location : this.warehouseId
          }
          data['equipmentTypeId'] = this.equipmentTypeIds[this.equipmentTypeIds.length - 1] || null
          console.log(data, 'data');
          if (this.is_update) {
            //修改
            data['id'] = this.updateId
            // console.log((data), '------');
            updateEquipment(data).then(res => {
              this._addCommonFn(res, formName)
              this.getSelectElAllNo()
            })
          } else {
            //新增
            addEquipment(data).then(res => {
              // console.log(res, 'res');
              this._addCommonFn(res, formName)
            })
          }
        } else {
          // console.log('error submit!!');
          this.$notify.info('请填写信息')
          return false;
        }
      });
    },
    //添加成功公共处理函数
    _addCommonFn (res, formName) {
      if (res.data.code === 200) {
        this.$notify.success(res.data.message)
        this.addModel = false
        this.equipmentTypeIds = []
        this.$refs[formName].resetFields();
        this.handleList()
      } else {
        this.$notify.error(res.data.message)
      }
    },
    seeModeBtn (row, index) {
      //console.log(row);
      // console.log(this.setEquipmentLedger);
      this.setEquipmentLedger(row)
      /*this.examineModeType = 1;
      this.examineMode = true
      this.isTaizhang = 1;
      this.activeName = '0'*/
      /*this.$router.push({ path:'/equipmentLedger'})*/
      this.$router.push({
        path: this.$router.$avueRouter.getPath({
          name: '1设置',
          src: '/ledger/equipmentLedger'
        }),
        query: { id: row.id }
      });

    },
    examineModeBtn (row, index) {
      this.examineModeType = 2;
      this.examineMode = true
    },
    updModeBtn (row, index) {
      //修改设备列表项
      
      this.is_update = true
      this.updateId = row.id
      this.isAsEl = row.isAsEl
      this.examineModeType = 3;
      this.examineMode = true
      this.modelTitle = '修改设备'
      this.selectELList= this.copySelectELList
      let res = this.gridData.find(item => item.id == row.id)
      this.equipmentTypeId = res.equipmentTypeId //设备类别id
      this.warehouseId = res.warehouseId //位置id
      this.laboratoryId = res.laboratoryId
      this.equipmentTypeIds = serverArr(this.equipmentType, res.equipmentTypeId) // [getDepartmentTreeOfId(this.equipmentType, res.equipmentTypeId).id]
      this.addForm = {
        coded: res.coded,
        name: res.name,
        marking: res.marking,
        brand: res.brand,
        supplier: res.supplier,
        deviceId:res.deviceId,
        elcId:res.elcId,
        price: res.price,
        equipmentType: res.equipmentType,
        purchasing_date: new Date(res.purchasingDate),
        pictureUrl: res.pictureUrl,
        phoneNum: res.phoneNum,
        locations: res.location,
        options: res.options,
        is_maintain: res.isMaintain,
        maintain_cycle: res.maintainCycle,
        correct_cycle: res.correctCycle,
        maintain_waring: res.maintainWaring,
        is_monitor: res.isMonitor,
        voltage_waring: res.voltageWaring,
        electricity_waring: res.electricityWaring,
        is_transmission: res.isTransmission,
        mode: res.mode,
        interface_type: res.interfaceType,
        equipment_site: res.equipmentSite,
        port: res.port,
        is_run: res.isRun,
        stop_cause: res.stopCause,
        location: res.location === 0 ? res.warehouseId : res.laboratoryId
      }
      this.imageUrl = website.axiosUrl + res.pictureUrl;
      console.log(this.imageUrl)
      this.addModel = true
    },
    tableDelBtn (row, index) {
      this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'
      }).then(() => {
        //请求--删除
        deleteEquipment({ id: row.id }).then(res => {
          if (res.data.code === 200) {
            this.handleList()
            this.$notify.success('删除成功');
          } else {
            this.$notify.error(res.data.message)
          }
        })
        // this.$delete(this.gridData, index)

      });
    },
    //设备类别管理
    eqiupmentTypeManage () {
      this.typeMode = true
      // this.dialogTypeManageVisible = true;
    },
    //仅显示能传输数据设备
    searchFormSubmit () {
      console.log(this.searchForm);
      let data = {
        isTransmission: this.searchForm.checked ? 0 : null,
        name: this.searchForm.name,
        // equipmentCoding: this.searchForm.coded,
        coded: this.searchForm.coded, //编码
        //equipmentTypeId: this.seachEquipmentTypeId[this.seachEquipmentTypeId.length-1],
        marking: this.searchForm.model, //型号
        page: 1,
        size: this.page.pageSize
      }
      this._getList(data)
    },
    //获取设备列表数据
    handleList (search) {
      let data = {
        page: this.page.currentPage,
        size: this.page.pageSize
      };
      if (search) {
        data['page'] = 1
        switch (search.state) {
          case 0: // 已启用
            data['isRun'] = search.state //设备状态
            data['stopCause'] = null //设备状态
            break;
          case 1: // 已停用
            data['isRun'] = search.state //设备状态
            data['stopCause'] = 3 //设备状态
            break;
          case 2: // 保养中
            data['isRun'] = 1 //设备状态
            data['stopCause'] = 0 //设备状态
            break;
          case 3: // 校准中
            data['isRun'] = 1 //设备状态
            data['stopCause'] = 1 //设备状态
            break;
          case 4: // 维修中
            data['isRun'] = 1 //设备状态
            data['stopCause'] = 2 //设备状态
            break;
          case 5: // 已报废
            data['isRun'] = 1 //设备状态
            data['stopCause'] = 4 //设备状态
            break;
          default:
            break;
        }
        data['equipmentState'] = search.state //设备状态
        data['options'] = search.appointment //预约
        data['warning'] = search.maintainWaring //监控
        data['equipmentTypeId'] = this.seachEquipmentTypeIds[this.seachEquipmentTypeIds.length - 1]
        data['location'] = search.location
      }
      console.log(data);
      this._getList(data)
    },
    //获取设备列表数据 ---发请求
    _getList (data) {
      this.tableLoading = true;
      getEquipmentList(data)
        .then(res => {
          console.log(res, '---');
          if (res.data.code === 200) {
            const data = res.data.data;
            this.gridData = data.list;
            this.page.total = data.total;
            this.page.pageSize = data.pageSize
            this.page.currentPage = data.pageNum
            this.tableLoading = false;
          } else {
            this.$notify.error(res.data.message)
          }
        });
    },
    getshebeiList(){
       getEquipmentList({name:'智能插座',page: 1,size: 100})
        .then(res => {
          if (res.data.code === 200) {
              console.log(res.data,'---444--')
              this.shebeiList = res.data.data.list
          }
        });
    },
    // 切换页面
    currentPage (val) {
      // console.log(val);
      this.page.currentPage = val;
      this.handleList()
    },
    sizeChange (val) {
      // console.log(val);
      this.page.pageSize = val
      this.handleList()
    },
    //上传图片成功
    handleAvatarSuccess (response, file) {
      this.is_picture_urlClass = true;
      // this.imageUrl = URL.createObjectURL(file.raw);
      console.log(response, file);
      if (response.code === 200) {
        this.addForm.pictureUrl = response.data
        console.log("二级:"+response.data)

        this.imageUrl = URL.createObjectURL(file.raw);
        console.log("一级:"+URL.createObjectURL(file.raw))
        this.$notify.success("图片上传成功");
      } else {
        this.$notify.error(response.message);
      }
    },
    // 图片上传失败
    uploadError (err, file) {
      this.$notify.error(err);
    },
    //上传图片前的操作
    // beforeAvatarUpload (file) {
    //   const isJPG = file.type === 'image/jpeg';
    //   const isLt2M = file.size / 1024 / 1024 < 2;
    //   if (!isJPG) {
    //     this.$notify.error('上传头像图片只能是 JPG 格式!');
    //   }
    //   if (!isLt2M) {
    //     this.$notify.error('上传头像图片大小不能超过 2MB!');
    //   }
    //   return isJPG && isLt2M;
    // },
    radioChange () {
      this.$refs['addForm'].validate((valid) => {
        return false;
      });
    },
    stateModeBtn (state) {
      // console.log(this.selectionRow.id)
      if (!this.selectionRow.id) {
        this.$notify.info('请选择你需要操作的项目')
        return;
      }
      console.log(state);
      const stateBtnName = ['启用', '停用', '提交', '提交', '提交']
      const stateTitle = ['启用确认', '停用确认', '维保申请单', '故障报停单', '报废申请单']
      this.stateMode = true;
      this.stateModeBtnName = stateBtnName[state]
      this.stateModeTitle = stateTitle[state]
      this.stateModeFormIs = state; //停用
      if (state >= 2) {
        this.newspaperStop.typeTitle = stateTitle[state].slice(0, 2) + '类型'
        this.newspaperStop.docsTitle = stateTitle[state].slice(0, 2) + '说明'
      }
    },
    selectionChange (selection) {
      console.log(selection);
      this.selectionRow = selection[selection.length - 1] || { id: '' }
    },
    // success 处理
    _successInfo (res, shenqi = false) {
      if (res.data.code === 200) {
        this.$notify.success(res.data.message)
        this.handleList();
        this.stateMode = false
        this.selectionRow = { id: '' }
        if (shenqi) {
          this.$refs['newspaperStop'].resetFields();
        }
      } else {
        this.$notify.error(res.data.message)
      }
    },
    //state confirm
    menuModeFormBtn () {
      const state = this.stateModeFormIs //操作按钮
      const { id } = this.selectionRow
      if (state === 0) {//启用
        //选择项id
        upWalk({ id }).then(res => {
          this._successInfo(res)
        })
      } else if (state === 1) {//停用
        if (this.stateModeForm.stop_cause === '') {
          this.$notify.info('请选择停用类型')
          return;
        }
        let params = {
          id,
          stopCause: this.stateModeForm.stop_cause
        }
        console.log(params);
        downBack(params).then(res => this._successInfo(res))
      } else {
        this.$refs['newspaperStop'].validate(valid => {
          // console.log(v, 'v');
          if (valid) {
            if (state === 2) { //维保申请
              let params = {
                // equipmentId: id,
                // maintenanceType: this.newspaperStop.type,
                // maintenanceInstructions: this.newspaperStop.docs
                equipmentId: id,
                maintenanceType: this.newspaperStop.type,
                remakes: this.newspaperStop.docs
                // applicationTime: this.formatDate() //申请时间（取得本地时间）
              }
              console.log(params, '维保申请');
              addMaintenanceAppointment(params).then(res => this._successInfo(res, true))
            } else if (state === 3) { // 故障报停
              let params = {
                equipmentId: id,
                troubleStatus: this.newspaperStop.type,
                troubleNote: this.newspaperStop.docs
              }
              addTrouble(params).then(res => this._successInfo(res, true))
            } else if (state === 4) { //报废申请
              let params = {
                equipmentId: id,
                // scrapStatus: this.newspaperStop.type,
                scrapType: this.newspaperStop.type,
                maintenanceInstructions: this.newspaperStop.docs
              }
              addScrapApplication(params).then(res => this._successInfo(res, true))
            }
          } else {
            this.$notify.info('请填写信息')
            return false;
          }
        })
      }
    },
    // close  stateMode
    menuModeFormBtnClose () {
      this.stateMode = false
      // this.$refs['newspaperStop'].resetFields();
    },
    handleClick (tab, event) {
      if (this.activeName == '-1') {
        this.isTaizhang = 0;
      }
    },
    // 获取设备类别数据
    _getDepartmentList() {
      getDevList().then(res => {
        if (res.data.code == 200) {
          this.equipmentType = DepartmentTreeVChildrenNull(res.data.data)
          this.getDepartmentTree = DepartmentTreeVChildrenNull(res.data.data);//设备tree
          this.seachEquipmentType = DepartmentTreeVChildrenNull(res.data.data,[{label:'全部',value:''}])

          this.devTypeArr = jsonToArray(res.data.data)
          // this.departmentOption = res.data.data;
        } else {
          this.$notify.error(res.data.message)
        }
      });
    },

    // 点击分类管理
    typeManage () {
      this.dialogTypeManageVisible = true;
    },
    // 新增--部门管理 - 一级部门
    appendTreeType () {
      this.dialogFormTypeVisible = true;
    },
    // 新增--部门管理 - 子级部门
    addDepartment (node, data) {
      this.dialogFormType.parentId = data.value
      this.dialogFormTypeVisible = true;
    },
    //   点击树
    handleNodeClick (data) {
      // console.log(data);
    },
    // 修改标题--部门管理
    editTree (node, data) {
      this.dialogTypeTitle.name = data.label
      this.dialogTypeTitle.id = data.id
      this.dialogTypeTitle.parentId = getDepartmentTreeOfValue(this.getDepartmentTree, data.id)
      this.dialogTypeTitleVisible = true;
    },
    // 删除--部门管理
    removeTree (node, data) {
      /*const parent = node.parent;
      const children = parent.data.children || parent.data;
      const index = children.findIndex(d => d.id === data.id);
      children.splice(index, 1);*/
      this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'
      }).then(() => {
          //请求--删除
          delDev({ id: data.id }).then(res => {
              if (res.data.code === 200) {
                  this._getDepartmentList();
                  this.$notify({ title: '操作成功', message: "删除成功!", type: 'success', });
              } else {
                  this.$notify.error({ title: '操作失败', message: res.data.message, type: 'danger', });
              }
          })
      });
    },
    // 确认修改--部门管理
    handleEditTypeTitle (formName) {
        this.$refs[formName].validate(valid => {
        if (valid) {
            let data = this.dialogTypeTitle;
            data.parentId = this.dialogTypeTitle.parentId[this.dialogTypeTitle.parentId.length-1]
            editDev(data).then(res=>{
                if(res.data.code==200){
                    this.$refs[formName].resetFields();
                    this.$notify({ title: '操作成功', type: 'success', message: '已修改成功!'});
                    this.dialogTypeTitleVisible = false;
                    this._getDepartmentList()
                } else {
                    this.$notify.error({ title: '操作失败', message: res.data.message, type: 'danger', });
                }
            })

        }
      });
    },
    // 增加--选中树--部门管理
    handleTree (value) {
      // console.log(value);
      //  this.dialogFormType.parentId=value;
    },
    // 增加部门管理---input 回车事件
    changeInput (value) {

      // console.log(this.dialogFormType.content.split('/n'));
      // console.log(value);
    },
    // 确认新增-部门管理--树
    handleAddType (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          let text = this.dialogFormType.content.replace(/\n/g, ';')
          let textArr = text.split(';')
          textArr = textArr.filter(item => item !== '')
          text = [];
          textArr.forEach(item=>{
              text.push({
                  name : item ,
                  parentId : this.dialogFormType.parentId
              })
          })
          addDev(text).then(res => {
              if(res.data.code==200){
                  this.$refs[formName].resetFields();
                  this.$notify({ title: '操作成功', type: 'success', message: '已成功添加!'});
                  this.dialogFormTypeVisible = false;
                  this._getDepartmentList()
              } else {
                  this.$notify.error({ title: '操作失败', message: res.data.message, type: 'danger', });
              }
          })
        }
      });
    },
    // 仓库 清空
    qingNull(val) {
      console.log(val)
      this.addForm.options = ''
    },

  }
}
</script>

<style lang="scss" scoped>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.default-head {
  font-size: 120px;
  border: 1px solid #606266;
  border-radius: 5px;
  padding: 30px 30px;
}
.avue-crud__menu {
  min-height: 0px;
  margin-bottom: 0px;
}
.el-row {
  margin-left: 20px !important;
  margin-bottom: 20px;
  .el-col-3 {
    font-weight: 600;
  }
}
.lineDiv {
  border-top: 1px solid #d6d6d6;
  margin: 0px 1% 20px 25px;
  width: 90%;
}
.el-dialog__body {
  padding-top: 15px;
  padding-bottom: 0px;
}
</style>

<style lang="scss">
.zindex1 > .el-form-item__content {
  z-index: -1;
}
.picture_url {
  min-height: 175px;
}
.picture_urlClass div[class~="el-upload"] {
  display: none;
}
.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
}
thead .el-checkbox__inner {
  display: none !important;
}
</style>

